var repassword = new Vue({
    el: "#repassword",
    data() {
        return {
            services: services,
            userInfo:"",
            oldPassword:"",
            rePwd:"",
            newPassword:"",
        }
    },
    created () {
        this.userInfo = LoginStatus();
        if(this.userInfo==false)
            return false;
    },
    methods:{
        submit: function () {
            var that = this;
            //数据校验
            if(that.oldPassword==""||that.oldPassword==null){
                layerMsg("旧密码不为空")
                return false;
            }
            if(that.newPassword==""||that.newPassword==null){
                layerMsg("新密码不为空")
                return false;
            }
            if(that.rePwd==""||that.rePwd==null){
                layerMsg("确认密码不为空")
                return false;
            }
            if(that.oldPassword.length<6||that.newPassword.length<6||that.rePwd.length<6){
                layerMsg("密码长度不小于6位")
                return false;
            }
            if(that.newPassword!=that.rePwd){
                layerMsg("密码不一致");
                return false;
            }
            //ajax请求
            $.ajax({
                type:'post',
                async:false,
                url:that.services+"/user/password",
                contentType:"application/json;charset=utf-8",
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                data:JSON.stringify({
                    'oldPassword':that.oldPassword,
                    'newPassword':that.newPassword,
                }),
                success: function(res) {
                    var check = ApiLoginStatus(res)
                    if(check==false)
                        return false;
                    if(res.success){
                        layerMsg(res.message+",请重新登录")
                        $.cookie('userInfo', '', {expires: -1});
                        setTimeout(function() {
                            window.location.href="/login.html" ;
                        },3000);
                    }else{
                        layerMsg(res.message)
                    }
                }
            })
        }
    }
});

